﻿@{
    Layout = null;
    var objPrimaryKey = Model.ColumnInfos.First();
    var objExceptPrimaryKey = Model.ColumnInfos.Except(new List<ColumnInfo> { objPrimaryKey }).Where(c => c.IsDisplay).ToList();
    var objSingleImages = Model.ColumnInfos.Where(c => c.ControlName == "UpLoadImage" || c.ControlName == "UpLoadNativeImage").ToList();
    string entityName = Model.Name;
    List<string> listControls = new List<string> { "NumberBox", "CheckBox", "DateTimeBox", "UpLoadImage", "UpLoadNativeImage", "UpLoadImages", "Ueditor" };
    int i = 0;
}@inherits  BuildCodeViewPage<TableInfo>
@@using @(Model.Namespace).DataEntity;
@@inherits CMSWebViewPage<@entityName>
@@{
    ViewBag.Title = "@Model.Description";
    Layout = "~/Views/Shared/_EditLayout.cshtml";
}
@@section Head{
    @@*@@Html.CreateDialogSource()*@@
    @@*@@Html.CreateUpLoadSource()*@@
    @@*@@Html.CreateEditorSource()*@@
}
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:false" class="xhidden">
        <div class="top-block">
            @@CurrentButtonTool.Create()
        </div>
        <form id="fr_@entityName.ToLower()" method="post" @Raw(objSingleImages.IsNoNull() ? "enctype=\"multipart/form-data\"" : "")>
            @@*@@Html.AntiForgeryToken()*@@
            <table class="tblContent">
                <colgroup>
                    <col class="colTitle" />
                    <col class="colContent" />
                </colgroup>
            @foreach (var objColumnInfo in objExceptPrimaryKey)
            { 
                <tr>
                    <td>@if (objColumnInfo.IsRequired && !listControls.Contains(objColumnInfo.ControlName))
                        {<span class="txtNoNull">*</span>}@objColumnInfo.Description:</td>
                    <td>
                        @if (i == 0)
                        {
                        <tj>@@Html.Hidden("objProvide.@objPrimaryKey.Name", Model.@objPrimaryKey.Name, false)</tj>
                        }
                @switch (objColumnInfo.ControlName)
                {
                    case "Hidden":
        <tj>@@Html.Hidden("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, false)</tj>
                        break;
                    case "StringBox":
        <tj>@@Html.StringBox("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, @objColumnInfo.IsRequired.ToString().ToLower(),  "请输入@(objColumnInfo.Description)", null, ValidType.Length(@objColumnInfo.Datalength))</tj>
                        break;
                    case "NumberBox":
        <tj>@@Html.NumberBox("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</tj>
                        break;
                    case "ComboBox":
        <tj>@@Html.ComboBox("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, @objColumnInfo.IsRequired.ToString().ToLower(), "请选择@(objColumnInfo.Description)", new List<SelectListItem>{

                        })</tj>
                        break;
                    case "CheckBox":
        <tj>@@Html.CheckBox("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, 1, 0)</tj>
                        break;
                    case "DateTimeBox":
        <tj>@@Html.DateTimeBox("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</tj>
                        break;
                    case "CheckBoxList":
        <tj>@@Html.CheckBoxList("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, @objColumnInfo.IsRequired.ToString().ToLower(), new List<SelectListItem> {

                        })</tj>
                        break;
                    case "RadioButtonList":
        <tj>@@Html.RadioButtonList("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, @objColumnInfo.IsRequired.ToString().ToLower(), new List<SelectListItem> {

                        })</tj>
                        break;
                    case "UpLoadImage":
        <tj><ul class="single-row">
                            <li>@@Html.UpLoadImage(1, "objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</li>
                            <li>@@Html.CheckClearValue("清除配图", "objProvide.@objColumnInfo.Name")</li>
                        </ul></tj>
                        break;
                    case "UpLoadNativeImage":
        <tj>@@Html.UpLoadNativeImage(0, "objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</tj>
                        <tj>@@Html.CheckClearValue("清除配图", "objProvide.@objColumnInfo.Name")</tj>
                        break;
                    case "UpLoadImages":
        <tj>@@Html.UpLoadImages(0, "objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</tj>
                        break;
                    case "TextArea":
        <tj>@@Html.TextArea("objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name, 5, 100)</tj>
                        break;
                    case "Ueditor":
        <tj>@@Html.Ueditor(0, 0, "objProvide.@objColumnInfo.Name", Model.@objColumnInfo.Name)</tj>
                        break;
                }
                    </td>
                </tr>
                i++;
            }
            </table>
        </form>
    </div>
@if (objSingleImages.IsNoNull())
{ 
    <div class="image-preview" title="图片预览" data-options="region:'east',border:true">
    @foreach (var objImage in objSingleImages)
    { 
        <div>
            <h1>@objImage.Description</h1>
            @@Html.ImagePreview("objProvide.@objImage.Name", Model.@objImage.Name)
        </div>
    }
    </div>
}
</div>
@@section Bottom{
    <script type="text/javascript">
        function Save() {
            var objFormEntity = new FormEntity("#fr_@entityName.ToLower()");
            objFormEntity.url = "/@entityName.ToLower()/save";
            objFormEntity.submitSuccess = function (InvokeResult) {
                if (InvokeResult.ResultCode == "Success") {
                    ShowMessage(InvokeResult.ResultMessage);
                    Back();
                } else {
                    ShowMessage(InvokeResult.ResultMessage);
                }
            };
            objFormEntity.isClearData = false;
            objFormEntity.submit();
        }
        function Back() {
            window.location = "/@entityName.ToLower()";
        }
    </script>
}

